<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>配置权限</title>
	<meta name="keywords" content="" />
    <meta name="description" content="LarryCMS Version:1.09" />
	<meta name="Author" content="larry" />
	<meta name="renderer" content="webkit">	
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<link rel="Shortcut Icon" href="/favicon.ico" />
	<!-- load css -->
	<link rel="stylesheet" type="text/css" href="/static/common/frame/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/common/css/gobal.css" media="all">
    <link rel="stylesheet" type="text/css" href="/static/css/common.css" media="all">
	<link rel="stylesheet" type="text/css" href="/static/common/plus/zTree/css/zTreeStyle.css" media="all">
	<style type="text/css" media="screen">
		ul.ztree li span.button.switch{margin-right:5px}
		ul.ztree>li{background: #dae6f0;padding: 8px;}
		ul.ztree>li ul li{background: #eef5fa;margin-top: 8px;padding: 5px;}
		ul.ztree>li ul li ul li{background: #f6fbff;padding: 5px;}
		ul.ztree>li ul li ul li ul li{background: #fff;padding: 5px;}
		ul.ztree ul ul ul li{display:inline-block;}
		ul.ztree>ul li>ul>li{padding:5px}
		ul.ztree>ul li>ul{margin-top:12px}
		ul.ztree>ul li{padding:15px;padding-right:25px}
		ul.ztree>ul li{white-space:normal!important;background: #01AAED}
		ul.ztree li{white-space:inherit;}
		ul.ztree>li>a>span{font-size:15px;font-weight:700}
	</style>
</head>
<body>
<div style="margin: 15px 10px;" class="fadeInUp animated">
	<form class="layui-form layui-form-pane">
		<div class="layui-form-item">
			<ul id="treeDemo" class="ztree"></ul>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="button" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
				<button id="goback" class="layui-btn layui-btn-primary" type="button">关闭</button>
			</div>
		</div>
	</form>
</div>
<!-- 加载js文件 -->
<script type="text/javascript" src="/static/common/frame/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/common.js"></script>
<script type="text/javascript" src="/static/common/plus/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/static/common/plus/zTree/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="/static/common/plus/zTree/js/jquery.ztree.excheck.min.js"></script>
<script type="text/javascript">
    var setting = {
        check:{enable: true},
        view: {showLine: false, showIcon: false, dblClickExpand: false},
        data: {
            simpleData: {enable: true, pIdKey:'pid', idKey:'id'},
            key:{name:'title'}
        }
    };
    var zNodes ={$data};
    function setCheck() {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        zTree.setting.check.chkboxType = { "Y":"ps", "N":"ps"};
    }
    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    setCheck();
    //表单顶部按钮操作
    $('#goback').on('click',function(){
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    });
    layui.use(['form', 'layer'], function () {
        var form = layui.form, layer = layui.layer;
        form.on('submit(submit)', function () {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            // 提交到方法 默认为本身
            var treeObj=$.fn.zTree.getZTreeObj("treeDemo"),
                nodes=treeObj.getCheckedNodes(true),
                v="";
            for(var i=0;i<nodes.length;i++){
                v+=nodes[i].id + ",";
            }
            var id = "{:input('id')}";
            $.post("{:url('setAuth')}", {'rules':v,'id':id}, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index);
                        //parent.location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
        })
    });
</script>
</body>
</html>